import React from 'react'
import WNavBar from '@components/global/navBar'
import StudyModel from '@models/studyModel'
import PackageModel from '@models/packageModel'
import JumpCell from '@components/global/jumpCell'
// @ts-ignore
import Styles from './index.scss'

interface PopInterface {
  title: string
  studyTypes: string[]
  packageTypes: string[]
}

const ConclusionPage = (props: PopInterface) => {

  return (
    <WNavBar title={ props.title } back={false}>
      <>
        <p className={ Styles['section-title'] }>学习总结</p>
        {
          props.studyTypes.map((item) => {
            return <JumpCell top={false} toPath={ `/conclusion/study/list?type=${item}` }>{ item }</JumpCell>
          })
        }
        <p className={ Styles['section-title'] }>封装</p>
        {
          props.packageTypes.map((item) => {
            return <JumpCell top={false} toPath={ `/conclusion/package/list?type=${item}` }>{ item }</JumpCell>
          })
        }
      </>
    </WNavBar>
  )
}

ConclusionPage.getInitialProps = async () => {
  const data = await Promise.all([StudyModel.loadTypes(), PackageModel.loadTypes()])
  return {
    title: '总结',
    layout: {
      type: 'tabBar',
      tabBar: 'conclusion'
    },
    studyTypes: data[0],
    packageTypes: data[1]
  }
}

export default ConclusionPage
